﻿using Common.Contract;
using Common.Contract.Customer.Identifier;
using Common.Contract.Customer.Record;
using Common.Contract.DataCenter.Record;
using Common.Contract.DataCenter.Request;
using Common.Service.Command;
using Common.Service.Queue;
using Common.Util;
using DataCenter.Configuration;
using DataCenter.Model.Interface;
using DataCenter.Model.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataCenter.ServiceCommand
{
    public class UpdateShopBilltoServiceCommand : ProviderQueueCommand<IProviderFactory, ShopBilltoRecord, ResponseRecord>
    {
        public UpdateShopBilltoServiceCommand(IProviderFactory provider) : base(provider) { }

        protected override void Validate(ShopBilltoRecord record)
        {
            if (record == null) throw new ArgumentNullException("request");
        }

        protected override bool OnExecute(ResponseRecord response)
        {
            var billpRecord = Record;
            var obj = new ShopBillto
            {
                BilltoCode = billpRecord.BilltoCode,
                //CreateDate = DateTime.Now,
                CreateUser = billpRecord.CreateUser,
                ModifyDate = DateTime.Now,
                ModifyUser = billpRecord.ModifyUser,
                ShopCode = billpRecord.ShopCode,
                SoTransferFlag = BooleanString.TRUE,
                SoTransferDate = DateTime.Now,
                UseFlag = billpRecord.UseFlag.HasValue ? billpRecord.UseFlag.Value.ToBooleanString() : null
            };
            var itemCheck = Providers.ShopBillto.Retrieve(Record.ShopCode, Record.BilltoCode);
            if (itemCheck == null)
            {
                var resultitem1 = Providers.ShopBillto.Add(obj);
            }
            else
            {
                var resultitem2 = Providers.ShopBillto.Update(obj);
            }
            return true;
        }
    }
}
